/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.ui.rich.full.controller;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.CubicCurve2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.QuadCurve2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

import br.ufmg.dees.insane.commons.controller.Controller;
import br.ufmg.dees.insane.commons.view.DrawingArea;
import br.ufmg.dees.insane.commons.view.Interface;
import br.ufmg.dees.insane.draw.AxisDraw;
import br.ufmg.dees.insane.draw.CubicCurveDraw;
import br.ufmg.dees.insane.draw.Draw;
import br.ufmg.dees.insane.draw.LineDraw;
import br.ufmg.dees.insane.draw.PointDraw;
import br.ufmg.dees.insane.draw.QuadCurveDraw;
import br.ufmg.dees.insane.model.Model;
import br.ufmg.dees.insane.model.geo.GControlPoint;
import br.ufmg.dees.insane.model.geo.GCubicCurve;
import br.ufmg.dees.insane.model.geo.GLine;
import br.ufmg.dees.insane.model.geo.GPoint;
import br.ufmg.dees.insane.model.geo.GQuadCurve;
import br.ufmg.dees.insane.model.geo.GeometricModel;
import br.ufmg.dees.insane.util.IPoint3d;

/** The geometric controller for this application.
 *
 * @author Fonseca, Flavio & Pitangueira, Roque
 * @since January 2004
 */
public class GeometricController implements Controller {

	private Model model;
	private GeometricModel gmodel;
	private DrawingArea da;
	private ArrayList<Draw> ctrlPoints = new ArrayList<Draw>();
	private ArrayList<Draw> points = new ArrayList<Draw>();
	private ArrayList<Draw> lines = new ArrayList<Draw>();
	private ArrayList<Draw> quads = new ArrayList<Draw>();
	private ArrayList<Draw> cubics = new ArrayList<Draw>();
	private ArrayList<Object> selections = new ArrayList<Object>();
    
//*****************************************************************************
	
    /**
     * The constructor method
     *
     * @see       Interface
     */
    public GeometricController(Model model, DrawingArea da) {
        this.model = model;
        this.da = da;
        this.gmodel = this.model.getGModel();
    }
    
//*****************************************************************************
	
    public void draw(Graphics2D g) {
        
        double nodeScale = model.getState().nodeScale;
        g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		
		Draw draw;
		Point2D p;
		Point ctrl;
		
		//Draws global axis if selected
		if (model.getState().getViewGlobalAxis()) {
			g.setColor(model.getState().globalAxisColor);
			draw = new AxisDraw();
			((AxisDraw)draw).setLabel1("X");
			((AxisDraw)draw).setLabel2("Y");
			draw.setLocation(new Point(10, da.getHeight()-10));
			draw.draw(g);
		}
		
		//Draws the Cubic Curves
		GCubicCurve gc;
		g.setColor(model.getState().lineColor);
		ListIterator cbs = cubics.listIterator();
        while(cbs.hasNext()) {
            draw = (Draw)cbs.next();
			gc = (GCubicCurve)draw.getRepresents();
			p = gc.getCtrl1();
			ctrl= da.getViewPoint(p);
			draw.setControl(ctrl);
			p = gc.getCtrl2();
			ctrl= da.getViewPoint(p);
			draw.setControl2(ctrl);
            draw.draw(g);
        }
		
		//Draws the Quadratic Curves
		GQuadCurve gq;
		g.setColor( model.getState().lineColor);
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			draw = (QuadCurveDraw)qcs.next();
			gq = (GQuadCurve)draw.getRepresents();
			p = gq.getCtrl();
			ctrl= da.getViewPoint(p);
			draw.setControl(ctrl);
			draw.draw(g);
		}
		
		//Draws the Lines
		g.setColor( model.getState().lineColor);
        ListIterator lns = lines.listIterator();
        while(lns.hasNext()) {
            draw = (Draw)lns.next();
            draw.draw(g);
        }
		
		//Draws the ControlPoints
		g.setColor(model.getState().controlPointColor);
		ListIterator pts = ctrlPoints.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			draw.setScale(nodeScale);
			draw.draw(g);
		}
		
		//Draws the Points
		g.setColor( model.getState().pointColor);
		pts = points.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			draw.setScale(nodeScale);
			draw.draw(g);
		}
		
    }
    
//*****************************************************************************
	
    public void fit() {
        
        //Calculating bounds
        if (points.size() >= 2){
            Point leftUp = new Point();
            Point rightDown = new Point();
            PointDraw po;
            ListIterator pts = points.listIterator();
            po = (PointDraw)pts.next();
            leftUp.x = po.getLocation().x;
            leftUp.y = po.getLocation().y;
            rightDown.x = po.getLocation().x;
            rightDown.y = po.getLocation().y;
            while (pts.hasNext()){
                po = (PointDraw)pts.next();
                if (po.getLocation().x < leftUp.x){
                    leftUp.x = po.getLocation().x;
                }
                if (po.getLocation().x > rightDown.x){
                    rightDown.x = po.getLocation().x;
                }
                if (po.getLocation().y < leftUp.y){
                    leftUp.y = po.getLocation().y;
                }
                if (po.getLocation().y > rightDown.y){
                    rightDown.y = po.getLocation().y;
                }
            }
            pts = ctrlPoints.listIterator();
            while (pts.hasNext()){
                po = (PointDraw)pts.next();
                if (po.getLocation().x < leftUp.x){
                    leftUp.x = po.getLocation().x;
                }
                if (po.getLocation().x > rightDown.x){
                    rightDown.x = po.getLocation().x;
                }
                if (po.getLocation().y < leftUp.y){
                    leftUp.y = po.getLocation().y;
                }
                if (po.getLocation().y > rightDown.y){
                    rightDown.y = po.getLocation().y;
                }
            }
            
            //Adding some border
            leftUp.x = leftUp.x - 15;
            leftUp.y = leftUp.y - 15;
            rightDown.x = rightDown.x + 15;
            rightDown.y = rightDown.y + 15;
            
            Point2D p1 = da.getWorldPoint(leftUp);
            Point2D p2 = da.getWorldPoint(rightDown);
            Rectangle2D r = new Rectangle2D.Double(p1.getX(), p2.getY(), p2.getX(), p1.getY());
            
			da.setZoom(r);
        }
    }
	
//*****************************************************************************
	
    public void add(Object obj) {
		
		if (obj instanceof GControlPoint) {
            GControlPoint p = (GControlPoint)obj;
            if(!this.contains(p)) {
   	            gmodel.addControl(p);
   	            ctrlPoints.add(new PointDraw(da.getViewPoint(p), p));
   	        }
        } else {
	        if (obj instanceof GPoint) {
	            GPoint p = (GPoint)obj;
	            if(!this.contains(p)) {
	   	            gmodel.add(p);
	   	            points.add(new PointDraw(da.getViewPoint(p), p));
	   	        }
	        }
	    }
		
		if (obj instanceof GLine) {
			GLine l = (GLine)obj;
			Point p1 = da.getViewPoint(l.getP1());
			Point p2 = da.getViewPoint(l.getP2());
			if(!this.contains(l)) {
				gmodel.add(l);
				lines.add(new LineDraw(p1, p2, l));
			}
		}
		
		if (obj instanceof GQuadCurve) {
			GQuadCurve q = (GQuadCurve)obj;
			Point p1 = da.getViewPoint(q.getP1());
			Point ctrl = da.getViewPoint(q.getCtrl());
			Point p2 = da.getViewPoint(q.getP2());
			if(!this.contains(q)) {
				gmodel.add(q);
				quads.add(new QuadCurveDraw(p1, ctrl, p2, q));
			}
		}
		
		if (obj instanceof GCubicCurve) {
			GCubicCurve c = (GCubicCurve)obj;
			Point p1 = da.getViewPoint(c.getP1());
			Point ctrl1 = da.getViewPoint(c.getCtrlP1());
			Point ctrl2 = da.getViewPoint(c.getCtrlP2());
			Point p2 = da.getViewPoint(c.getP2());
			if(!this.contains(c)) {
				gmodel.add(c);
				cubics.add(new CubicCurveDraw(p1, ctrl1, ctrl2, p2, c));
			}
		}
    }
	
//*****************************************************************************
	
	public boolean containsControl(Point2D po) {
        Point p = da.getViewPoint(po);
        Draw draw;
		
        ListIterator pts = ctrlPoints.listIterator();
        while(pts.hasNext()) {
            draw = (Draw)pts.next();
            if (draw.contains(p)) {
                return true;
            }
        }
		
		pts = points.listIterator();
        while(pts.hasNext()) {
            draw = (Draw)pts.next();
            if (draw.contains(p)) {
                return true;
            }
        }
		return false;
	}
	
//*****************************************************************************
	
    public boolean contains(Point2D po) {
        Point p = da.getViewPoint(po);
        Draw draw;
		
        ListIterator pts = points.listIterator();
        while(pts.hasNext()) {
            draw = (Draw)pts.next();
            if (draw.contains(p)) {
                return true;
            }
        }
		
		ListIterator lns = lines.listIterator();
		while(lns.hasNext()) {
			draw = (Draw)lns.next();
			if (draw.contains(p)) {
				return true;
			}
		}
		
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			draw = (Draw)qcs.next();
			if (draw.contains(p)) {
				return true;
			}
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			if (draw.contains(p)) {
				return true;
			}
		}
		return false;
	}
    
//*****************************************************************************	
	/*
    public boolean contains(Point2D po) {
	    Point p = da.getViewPoint(po);
        Draw draw;
		GCurve gc;
		
		ListIterator pts = ctrlPoints.listIterator();
        while(pts.hasNext()) {
            draw = (Draw)pts.next();
            if (draw.contains(p)) {
                return true;
            }
        }
		
		pts = points.listIterator();
        while(pts.hasNext()) {
            draw = (Draw)pts.next();
            if (draw.contains(p)) {
                return true;
            }
        }
		
		ListIterator lns = lines.listIterator();
		while(lns.hasNext()) {
			draw = (Draw)lns.next();
			if (draw.contains(p)) {
				return true;
			}
		}
		
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			draw = (Draw)qcs.next();
			if (draw.contains(p)) {
				return true;
			}
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			if (draw.contains(p)) {
				return true;
			}
		}
		return false;
	}
    */
//*****************************************************************************
	
    public boolean contains(Line2D l) {
        Point  p1 = da.getViewPoint(l.getP1());
        Point  p2 = da.getViewPoint(l.getP2());
        Draw draw;
        
        ListIterator lns = lines.listIterator();
        while(lns.hasNext()) {
            draw = (Draw)lns.next();
            if (draw.contains(p1) && draw.contains(p2)) {
                return true;
            }
        }
		
		return false;
	}
	
//*****************************************************************************
	
	public boolean contains(QuadCurve2D q) {
		return false;
	}
	
//*****************************************************************************
	
	public boolean contains(CubicCurve2D c) {
		return false;
	}
	
//*****************************************************************************
	
    public Point pick(Point p) {
        
        Draw draw;
        
        ListIterator pts = points.listIterator();
        while(pts.hasNext()) {
            draw = (Draw)pts.next();
            if (draw.contains(p)) {
                return draw.getLocation();
            }
        }
		
        pts = ctrlPoints.listIterator();
        while(pts.hasNext()) {
            draw = (Draw)pts.next();
            if (draw.contains(p)) {
                return draw.getLocation();
            }
        }
		
		ListIterator lns = lines.listIterator();
		while(lns.hasNext()) {
			draw = (Draw)lns.next();
			if (draw.contains(p)) {
				return draw.getLocation();
			}
		}
		
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			draw = (Draw)qcs.next();
			if (draw.contains(p)) {
				return draw.getLocation();
			}
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			if (draw.contains(p)) {
				return draw.getLocation();
			}
		}
        return p;
    }
    
//*****************************************************************************
	
	public void remove(Object obj) {
		if (obj instanceof GControlPoint) {
			gmodel.remove((GControlPoint)obj);
		}
		
		if (obj instanceof GPoint) {
			gmodel.remove((GPoint)obj);
		}
		
		if (obj instanceof GLine) {
			gmodel.remove((GLine)obj);
		}
		
		if (obj instanceof GQuadCurve) {
			gmodel.remove((GQuadCurve)obj);
		}
		
		if (obj instanceof GCubicCurve) {
			gmodel.remove((GCubicCurve)obj);
		}
		this.compose();
	}
	
//*****************************************************************************
	
    public List removeSelection() {
        
        ArrayList<Object> sel = new ArrayList<Object>();
        PointDraw pd;
		LineDraw ld;
		QuadCurveDraw qd;
		CubicCurveDraw cd;
        int index;
        
        ListIterator pts = ctrlPoints.listIterator();
        while(pts.hasNext()) {
            pd = (PointDraw)pts.next();
            if (pd.isSelected()) {
				GControlPoint p = (GControlPoint)pd.getRepresents();
				index = selections.indexOf(pd.getRepresents());
				selections.remove(index);
                gmodel.remove(p);
                sel.add(p);
            }
        }
        
        pts = points.listIterator();
        while(pts.hasNext()) {
            pd = (PointDraw)pts.next();
            if (pd.isSelected()) {
				GPoint p = (GPoint)pd.getRepresents();
				index = selections.indexOf(pd.getRepresents());
				selections.remove(index);
                gmodel.remove(p);
                sel.add(p);
            }
        }
		
		ListIterator lns = lines.listIterator();
		while(lns.hasNext()) {
			ld = (LineDraw)lns.next();
			if (ld.isSelected()){
				GLine l = (GLine)ld.getRepresents();
				index = selections.indexOf(ld.getRepresents());
				selections.remove(index);
				gmodel.remove(l);
				sel.add(l);
			}
		}
		
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			qd = (QuadCurveDraw)qcs.next();
			if (qd.isSelected()){
				GQuadCurve q = (GQuadCurve)qd.getRepresents();
				index = selections.indexOf(qd.getRepresents());
				selections.remove(index);
				gmodel.remove(q);
				sel.add(q);
			}
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			cd = (CubicCurveDraw)cbs.next();
			if (cd.isSelected()){
				GCubicCurve c = (GCubicCurve)cd.getRepresents();
				index = selections.indexOf(cd.getRepresents());
				selections.remove(index);
				gmodel.remove(c);
				sel.add(c);
			}
		}
		this.compose();
		return sel;
	}
    
//*****************************************************************************
	
	public void removeAll() {
		ctrlPoints.clear();
		points.clear();
		lines.clear();
		quads.clear();
		cubics.clear();
		gmodel.clear();
	}
	
//*****************************************************************************
    
    public void select(Point p) {
		
		Draw draw;
		int index;
		
		ListIterator pts = points.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			if (draw.contains(p)) {	
				if (draw.isSelected()) {
					draw.setSelected(false);
					index = selections.indexOf(draw.getRepresents());
					selections.remove(index);
					return;
				}else{
					draw.setSelected(true);
					selections.add(draw.getRepresents());
					return;
				}
			}
		}
		
		pts = ctrlPoints.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			if (draw.contains(p)) {	
				if (draw.isSelected()) {
					draw.setSelected(false);
					index = selections.indexOf(draw.getRepresents());
					selections.remove(index);
					return;
				}else{
					draw.setSelected(true);
					selections.add(draw.getRepresents());
					return;
				}
			}
		}
		
		ListIterator lns = lines.listIterator();
		while(lns.hasNext()) {
			draw = (Draw)lns.next();
			if (draw.contains(p)){
				if (draw.isSelected()) {
					draw.setSelected(false);
					index = selections.indexOf(draw.getRepresents());
					selections.remove(index);
					return;
				}else{
					draw.setSelected(true);
					selections.add(draw.getRepresents());
					return;
				}
			}
		}
		
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			draw = (Draw)qcs.next();
			if (draw.contains(p)){
				if (draw.isSelected()) {
					draw.setSelected(false);
					index = selections.indexOf(draw.getRepresents());
					selections.remove(index);
					return;
				}else{
					draw.setSelected(true);
					selections.add(draw.getRepresents());
					return;
				}
			}
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			if (draw.contains(p)){
				if (draw.isSelected()) {
					draw.setSelected(false);
					index = selections.indexOf(draw.getRepresents());
					selections.remove(index);
					return;
				}else{
					draw.setSelected(true);
					selections.add(draw.getRepresents());
					return;
				}
			}
		}
	}
	
//*****************************************************************************
    
	public void selectAll() {
		Draw draw;
		selections.clear();
		
		ListIterator pts = ctrlPoints.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			draw.setSelected(true);
			selections.add(draw.getRepresents());
		}
		
		pts = points.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			draw.setSelected(true);
			selections.add(draw.getRepresents());
		}
		
		ListIterator lns = lines.listIterator();
		while(lns.hasNext()) {
			draw = (Draw)lns.next();
			draw.setSelected(true);
			selections.add(draw.getRepresents());
		}
		
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			draw = (Draw)qcs.next();
			draw.setSelected(true);
			selections.add(draw.getRepresents());
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			draw.setSelected(true);
			selections.add(draw.getRepresents());
		}
	}
	
//*****************************************************************************
	
	public void unSelectAll() {
		Draw draw;
		
		ListIterator pts = ctrlPoints.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			draw.setSelected(false);
		}
		
		pts = points.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			draw.setSelected(false);
		}
		
		ListIterator lns = lines.listIterator();
		while(lns.hasNext()) {
			draw = (Draw)lns.next();
			draw.setSelected(false);
		}
		
		ListIterator qcs = quads.listIterator();
		while(qcs.hasNext()) {
			draw = (Draw)qcs.next();
			draw.setSelected(false);
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			draw.setSelected(false);
		}
	}
	
//*****************************************************************************
	
    public ArrayList getSelection() {
        return selections;
    }
	
//*****************************************************************************
	
	public void compose() {
		ctrlPoints.clear();
		points.clear();
		lines.clear();
		quads.clear();
		cubics.clear();
		
		Point2D po;
		Point p;
		ListIterator pts = gmodel.getControlPoints().listIterator();
		while (pts.hasNext()) {
			po = (Point2D)pts.next();
			p = da.getViewPoint(po);
			ctrlPoints.add(new PointDraw(p, po));
		}
		
		pts = gmodel.getPoints().listIterator();
		while (pts.hasNext()) {
			po = (Point2D)pts.next();
			p = da.getViewPoint(po);
			points.add(new PointDraw(p, po));
		}
		
		Line2D li;
		Point p1;
		Point p2;
		ListIterator lns = gmodel.getLines().listIterator();
		while (lns.hasNext()) {
			li = (Line2D)lns.next();
			p1 = da.getViewPoint(li.getP1());
			p2 = da.getViewPoint(li.getP2());
			lines.add(new LineDraw(p1, p2, li));
		}
		
		QuadCurve2D qu;
		Point ctrl;
		ListIterator qds = gmodel.getQuads().listIterator();
		while (qds.hasNext()) {
			qu = (QuadCurve2D)qds.next();
			p1 = da.getViewPoint(qu.getP1());
			ctrl = da.getViewPoint(qu.getCtrlPt());
			p2 = da.getViewPoint(qu.getP2());
			quads.add(new QuadCurveDraw(p1, ctrl, p2, qu));
		}
		
		CubicCurve2D cb;
		Point ctrl1;
		Point ctrl2;
		ListIterator cbs = gmodel.getCubics().listIterator();
		while (cbs.hasNext()) {
			cb = (CubicCurve2D)cbs.next();
			p1 = da.getViewPoint(cb.getP1());
			ctrl1 = da.getViewPoint(cb.getCtrlP1());
			ctrl2 = da.getViewPoint(cb.getCtrlP2());
			p2 = da.getViewPoint(cb.getP2());
			cubics.add(new CubicCurveDraw(p1, ctrl1, ctrl2, p2, cb));
		}
				
	}
	
//*****************************************************************************
	
	public Object get(Point2D po) {
		Point location = da.getViewPoint(po);
		Draw draw;
		
		ListIterator pts = ctrlPoints.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			if (draw.contains(location)) {
				return draw.getRepresents();
			}
		}
		
		pts = points.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			if (draw.contains(location)) {
				return draw.getRepresents();
			}
		}
		
		ListIterator lns = lines.listIterator();
		while(lns.hasNext()) {
			draw = (Draw)lns.next();
			if (draw.contains(location)){
				return draw.getRepresents();
			}
		}
		
		ListIterator qds = quads.listIterator();
		while(qds.hasNext()) {
			draw = (Draw)qds.next();
			if (draw.contains(location)){
				return draw.getRepresents();
			}
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			if (draw.contains(location)){
				return draw.getRepresents();
			}
		}
		
		return null;
	}
	
//*****************************************************************************
	
	public boolean isSelected() {
		Draw draw;
		
		ListIterator pts = ctrlPoints.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			if (draw.isSelected()) {
				return true;
			}
		}
		
		pts = points.listIterator();
		while(pts.hasNext()) {
			draw = (Draw)pts.next();
			if (draw.isSelected()) {
				return true;
			}
		}
		
		ListIterator lns = lines.listIterator();
		while(lns.hasNext()) {
			draw = (Draw)lns.next();
			if (draw.isSelected()){
				return true;
			}
		}
		
		ListIterator qds = quads.listIterator();
		while(qds.hasNext()) {
			draw = (Draw)qds.next();
			if (draw.isSelected()){
				return true;
			}
		}
		
		ListIterator cbs = cubics.listIterator();
		while(cbs.hasNext()) {
			draw = (Draw)cbs.next();
			if (draw.isSelected()){
				return true;
			}
		}
		return false;
	}

	public boolean contains(IPoint3d po) {
		// TODO Auto-generated method stub
		return false;
	}
	
//*****************************************************************************
}
